<template>
  <view class="container">
    <u-navbar
      :is-fixed="true"
      :border-bottom="false"
      :is-back="false"
      :background="{ background: '#e58b8a' }"
      title="我的"
      title-color="#fff"
    >
    </u-navbar>
    <view class="top">
      <view class="header" v-if="userInfo.id">
        <image class="avator" :src="userInfo.avator"></image>
        <view>{{userInfo.nickname}}</view>
      </view>
      <view class="header" v-if="!userInfo.id">
        <view @click="toLogin">请先登录</view>
      </view>
    </view>
    <view class="modify">
      <view class="flex-between" @click="updateUserInfo" v-if="userInfo.phone !== 'admin'">
        <view>信息管理</view>
        <image class="img" src="/static/images/arrow.svg"></image>
      </view>
      <view class="flex-between" @click="updatePassword" v-if="userInfo.phone !== 'admin'">
        <view>修改密码</view>
        <image class="img" src="/static/images/arrow.svg"></image>
      </view>
      <view class="flex-between" @click="userManage" v-if="userInfo.phone === 'admin'">
        <view>用户管理</view>
        <image class="img" src="/static/images/arrow.svg"></image>
      </view>
    </view>

    <view class="modify modify2" v-if="userInfo.phone !== 'admin'">
      <view class="flex-between" @click="sjb">
        <view>舌检表</view>
        <image class="img" src="/static/images/arrow.svg"></image>
      </view>
      <view class="flex-between" @click="qixue">
        <view>气血津液检查表</view>
        <image class="img" src="/static/images/arrow.svg"></image>
      </view>
    </view>

    <view class="btns" v-if="userInfo.id">
      <button class="submit" @click="logout">退出登录</button>
    </view>
    <!-- <view class="header" v-if="userInfo.id">
      <image class="avator" :src="userInfo.avator"></image>
      <view>{{userInfo.nickname}}</view>
    </view>
    <view class="header unlogin" v-if="!userInfo.id">
      <view class="avator">无</view>
      <view @click="toLogin">请先登录</view>
    </view>
    <view class="btns" v-if="userInfo.id">
      
      <button class="submit" @click="logout">退出登录</button>
    </view> -->
  </view>
</template>

<script>
export default {
  data() {
    return {
      userInfo: {}
    };
  },
  onShow() {
    uni.$off('login')
    uni.$once('login', (data) => {
      this.userInfo = data.userInfo
      this.userInfo.avator = `http://127.0.0.1:3000/${this.userInfo.avator}`
    })
  },
  mounted() {
    uni.getStorage({     
      key:'userInfo',
      success: (res) => {
        this.userInfo = res.data;
        this.userInfo.avator = `http://127.0.0.1:3000/${this.userInfo.avator}`
      }
    })
  },
  methods: {
    logout() {
      uni.removeStorage({
        key:'userInfo',
        success: () => {
			    this.$u.route('/pages/interest/login')
        }
      })
    },
    toLogin() {
			this.$u.route('/pages/interest/login')
    },
    updatePassword() {
      this.$u.route('/pages/interest/updatePassword', {
        userInfo: JSON.stringify(this.userInfo)
      })
    },
    updateUserInfo() {
      this.$u.route('/pages/interest/updateUserInfo', {
        userInfo: JSON.stringify(this.userInfo)
      })
    },
    userManage() {
			this.$u.route('/pages/manage/user')
    },
    sjb() {
      this.$u.route('/pages/interest/tone', {
        userInfo: JSON.stringify(this.userInfo)
      })
    },
    qixue() {
      this.$u.route('/pages/interest/blood', {
        userInfo: JSON.stringify(this.userInfo)
      })
    }
  },
};
</script>

<style lang="scss" scoped>
.container {
  min-height: 100vh;
  overflow: hidden;
  
  
}

.btns {
  padding: 30rpx;
}
.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 20rpx;

  .img {
    width: 40rpx;
    height: 40rpx;
  }
}

.submit {
  margin: 60rpx 30rpx 0;
  border: none;
  width: calc(100% - 60rpx);
  height: 86rpx;
  line-height: 86rpx;
  box-sizing: border-box;
  border-radius: 15rpx;
  background-color: #e58b8a;
  color: #ffffff;

  &::after {
    content: none;
  }

  &::before {
    content: none;
  }

  &[disabled='true'] {
    background: #e4e4e4;
    font-size: 36rpx;
    font-family: Source Han Sans CN;
    font-weight: 500;
    color: #ffffff;
  }
}

.top {
  width: 100%;
  height: 35vh;
  background: #e58b8a;
  padding-top: 10vh;

  .header {
    display: flex;
    align-items: center;
    padding: 30rpx;

    .avator {
      width: 140rpx;
      height: 140rpx;
      line-height: 140rpx;
      text-align: center;
      border-radius: 50%;
      color: #fff;
      margin-right: 30rpx;
    }

    .unlogin .avator {
      background: #7d8e8e;
    }
  }
}
.modify {
  width: 90%;
  margin: 0 auto;
  margin-top: -80rpx;
  background: #fff;
  border-radius: 20rpx;
  border: 1px solid gray;
  padding: 30rpx;
  display: flex;
  flex-direction: column;
  gap: 30rpx;
}
.modify2 {
  margin-top: 40rpx!important;
}
</style>
